# SET(CUR_ARCH "aarch64")
# SET(CUR_ARCH "armhf")
SET(CUR_ARCH "x86_64")
SET(PREFIX /home/sunjie/work)
# SET(PREFIX /home/zyx/work)

# 设置cuda版本
set(CUDA_VERSION "11.8")
# set(CUDA_VERSION "12.8")





if(CUDA_VERSION STREQUAL "11.8")
set(OPENCV_VERSION 4.8.0)
elseif(CUDA_VERSION STREQUAL "12.8")
set(OPENCV_VERSION 4.12.0)
else()
message("必须指定 CUDA_VERSION")
endif()



SET(CMAKE_C_FLAGS "-O3 -fPIC -ldl -lpthread -lrt")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 -fpermissive")
#  
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")


SET(UTILS_DIR ${PROJECT_SOURCE_DIR}/../base_util)
SET(STREAM_DIR ${PROJECT_SOURCE_DIR}/../stream)
SET(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common)
SET(TRTMODEL_DIR ${PROJECT_SOURCE_DIR}/tensorrt)

aux_source_directory(${UTILS_DIR} util_src)

SET(OTRTMODEL_SOURCE
    ${util_src}

    ${COMMON_DIR}/face_tool.cpp

    ${STREAM_DIR}/osd_text.cpp

    ${TRTMODEL_DIR}/../common/processor.cpp
    ${TRTMODEL_DIR}/../common/transforms.cpp
    ${TRTMODEL_DIR}/../common/visualize.cpp


    ${TRTMODEL_DIR}/../base_predictor.cpp
    ${TRTMODEL_DIR}/../model_manager.cpp
    ${TRTMODEL_DIR}/../infer_demo.cpp
    ${TRTMODEL_DIR}/base/trt_predictor.cpp
    ${TRTMODEL_DIR}/cls/cls_video.cpp
    ${TRTMODEL_DIR}/det/det_predictor.cpp
    # ${TRTMODEL_DIR}/ocr/rec_predictor.cpp
    # ${TRTMODEL_DIR}/engine.cpp
    ${TRTMODEL_DIR}/trtmodel_manager.cpp
    main.trt.cpp

)

set(TARGET_NAME model.trt)
add_executable(${TARGET_NAME} ${OTRTMODEL_SOURCE})

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/../)
include_directories(${UTIL_DIR})


# ffmpeg
SET(FFMPEG_PATH ${PREFIX}/lib/ffmpeg_build.cuda.${CUR_ARCH})
set(FFMPEG_LIB
    ${FFMPEG_PATH}/lib/libavcodec.so.58
    ${FFMPEG_PATH}/lib/libavfilter.so.7
    ${FFMPEG_PATH}/lib/libavformat.so.58
    ${FFMPEG_PATH}/lib/libavutil.so.56
    ${FFMPEG_PATH}/lib/libswresample.so.3
    ${FFMPEG_PATH}/lib/libswscale.so.5
)
include_directories(${FFMPEG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${FFMPEG_LIB})


# CUDA
SET(CUDA_PATH /usr/local/cuda-${CUDA_VERSION})
set(CUDA_LIB
    ${CUDA_PATH}/lib64/libcudart.so
    ${CUDA_PATH}/lib64/libnppc.so
    ${CUDA_PATH}/lib64/libnppig.so
    ${CUDA_PATH}/lib64/libnppicc.so
    ${CUDA_PATH}/lib64/libnppial.so
    ${CUDA_PATH}/lib64/libnppidei.so
)
include_directories(${CUDA_PATH}/include)
target_link_libraries(${TARGET_NAME} ${CUDA_LIB})


# TensorRT
SET(TRT_PATH ${PREFIX}/lib/TensorRT-10.10.0.31.cuda-${CUDA_VERSION})
set(TRT_LIB
    ${TRT_PATH}/lib/libnvinfer.so
    ${TRT_PATH}/lib/libnvonnxparser.so
)
include_directories(${TRT_PATH}/include)
target_link_libraries(${TARGET_NAME} ${TRT_LIB})


# opencv
SET(OPENCV_PATH ${PREFIX}/lib/opencv-${OPENCV_VERSION}/install.cuda.ffmpeg.cuda.${CUR_ARCH})
set(OPENCV_LIB ${OPENCV_PATH}/lib/libopencv_world.so.${OPENCV_VERSION})
include_directories(${OPENCV_PATH}/include/opencv4)
target_link_libraries(${TARGET_NAME} ${OPENCV_LIB})

# freetype
SET(FREE_PATH ${PREFIX}/lib/freetype-2.13.2/install.${CUR_ARCH})
set(FREE_LIB ${FREE_PATH}/lib/libfreetype.so.6.20.1)
include_directories(${FREE_PATH}/include/freetype2)
target_link_libraries(${TARGET_NAME} ${FREE_LIB})

#harfbuzz
SET(HARF_PATH ${PREFIX}/lib/harfbuzz-7.2.0/install.${CUR_ARCH})
set(HARF_LIB ${HARF_PATH}/lib/libharfbuzz.so.0.60720.0)
include_directories(${HARF_PATH}/include/harfbuzz)
target_link_libraries(${TARGET_NAME} ${HARF_LIB})


# openssl
SET(OPENSSL_PATH "${PREFIX}/lib/openssl-1.1.1q/install.${CUR_ARCH}")
set(OPENSSL_LIB
    ${OPENSSL_PATH}/lib/libcrypto.so.1.1
    ${OPENSSL_PATH}/lib/libssl.so.1.1
)
include_directories(${OPENSSL_PATH}/include)
target_link_libraries(${TARGET_NAME} ${OPENSSL_LIB})

# boost
SET(BOOST_PATH "${PREFIX}/lib/boost_1_67_0")
set(BOOST_LIB
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_filesystem.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_system.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_date_time.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_regex.a
)
include_directories(${BOOST_PATH})
target_link_libraries(${TARGET_NAME} ${BOOST_LIB})


# json
SET(JSONCPP_PATH ${PREFIX}/lib/jsoncpp-1.9.5/install.${CUR_ARCH})
set(JSONCPP_LIB ${JSONCPP_PATH}/lib/libjsoncpp.a)
include_directories(${JSONCPP_PATH}/include)
target_link_libraries(${TARGET_NAME} ${JSONCPP_LIB})

# spdlog
SET(SPDLOG_PATH ${PREFIX}/lib/spdlog-1.9.2/install.${CUR_ARCH})
set(SPDLOG_LIB ${SPDLOG_PATH}/lib/libspdlog.a)
include_directories(${SPDLOG_PATH}/include)
target_link_libraries(${TARGET_NAME} ${SPDLOG_LIB})

# yaml
SET(YAML_PATH ${PREFIX}/lib/yaml-cpp-yaml-cpp-0.6.2/install.${CUR_ARCH})
set(YAML_LIB ${YAML_PATH}/lib/libyaml-cpp.a)
include_directories(${YAML_PATH}/include)
target_link_libraries(${TARGET_NAME} ${YAML_LIB})

target_link_libraries(${TARGET_NAME} ${CMAKE_CXX_FLAGS})
